#ifndef NETWORKER_NET_POLLER_EPOLLPOLLER_H
#define NETWORKER_NET_POLLER_EPOLLPOLLER_H

#include "networker/net/Poller.h"

#include <vector>

struct epoll_event;

namespace networker
{
namespace net
{
    // IO Multiplexing with epoll(4).
    class EPollPoller: public Poller
    {
        private:
            typedef std::vector<struct epoll_event> EventList;

            int epollfd_;

            EventList events_;

        public:
            EPollPoller(EventLoop *loop);

            ~EPollPoller() override;

            Timestamp poll(int timeoutMs, ChannelList *activeChannels) override;

            void updateChannel(Channel *channel) override;
            void removeChannel(Channel *channel) override;
        
        private:
            static const int kInitEventListSize = 26;

            static const char* operationToString(int op);

            void fillActiveChannels(int numEvents, ChannelList* activeChannels) const;

            void update(int operation, Channel *channel);
    };
};
};

#endif